home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-06-16 | 3.3 KB | 111 lines | [TEXT/CWIE] |
- /*
- File: HelloWorld.cp
-
- Copyright: © 1998 by Apple Computer, Inc., all rights reserved.
-
- */
-
- /*
- * StExample
- *
- * A set of useful utility classes for using Navigation Services.
- * Requires building with CodeWarrior Pro2.
- *
- * Sample to show StNavGetFile and StNavPutFile classes
- * To Compile it:
- * 1 - Place an alias to Navigation.h (from SDK) in your project folder.
- * 2 - Include NavigationLib (from SDK) in your project.
- * To Run it:
- * 1 - Place an alias to Navigation library (from SDK) in same folder as target output.
- */
-
- //
- // You may incorporate this sample code into your applications
- // without restriction. This sample code has been provided "AS
- // IS" and the responsibility for its operation is 100% yours.
- // You are not permitted to redistribute the source as "Apple
- // sample code" after having made changes. If you're going to
- // re-distribute the source, we require that you make it clear
- // in the source that the code was descended from Apple sample
- // code, but that you've made changes.
- //
-
- #include <iostream>
- #include "StNavServices.h"
-
- #ifndef __NAVIGATION__
- #include "Navigation.h"
- #endif
-
- #ifndef _H_UAppleEventsMgr
- #include <UAppleEventsMgr.h>
- #endif
-
- pascal OSErr myOpen ( FSSpecPtr spec );
- pascal void myEvent ( NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD );
-
- // demonstrates open call for StNavGetFile
- pascal OSErr myOpen ( FSSpecPtr spec )
- {
- cout << "Open " << p2cstr ( spec->name ) << endl;
- return noErr;
- }
- RoutineDescriptor rdopen = BUILD_ROUTINE_DESCRIPTOR ( StNavGetFileOpenProcInfo, myOpen );
-
- // demonstrates how to handle event callbacks from Navigation Services
- pascal void myEvent ( NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD )
- {
- long ud = callBackUD;
- if ( callBackSelector == kNavCBEvent && callBackParms->eventData.event->what == updateEvt )
- cout << "Update" << endl;
-
- }
- RoutineDescriptor rdevt = BUILD_ROUTINE_DESCRIPTOR ( uppNavEventProcInfo, myEvent );
-
- int main()
- {
- cout << "StNavServices:\nA 'stack-based' object example for using Navigation Services.\n" << endl << endl;
-
- OSErr err;
- FSSpec spec;
-
- // way simple way to get a spec to a single file
- StNavGetFile gf( &err, &spec );
-
- // more options for getting files
- FSSpecArrayPtr specs;
- NavReplyRecord navreply; // use OUR reply record
-
- // use this type list instead of application's open resourece
- NavTypeListHandle tlh = StNavGetFile::MakeTypeList ( 'ttxt', 4, 'ttro', 'PICT', 'TEXT', 'MooV' );
- long numspecs;
-
- StNavGetFile gf1( &err, &specs, &numspecs, &rdopen, &navreply, false, true, &rdevt, nil, nil, tlh, 0xaabbccdd );
-
- if ( err == noErr )
- NavDisposeReply ( &navreply ); // if we supply it, we dispose of it
-
- DisposeHandle ( (Handle) tlh );
-
- // use StNavPutFile within a block which closes the file
- {
- FSSpec pspec;
- NavReplyRecord preply;
- StNavPutFile pf( &err, 'TEXT', 'ttxt', &pspec, &preply, &rdevt );
- if ( err == noErr )
- {
- if ( preply.replacing )
- FSpDelete(&pspec);
- FSpCreate(&pspec, 'ttxt', 'TEXT', smSystemScript);
- short refNum;
- FSpOpenDF(&pspec, fsWrPerm, &refNum);
- long count = sizeof ( "Smile :-)");
- FSWrite(refNum, &count, "Smile :-)");
- FSClose(refNum);
- }
- } // StNavPutFile destructor will finish things up
-
- return 0;
- }
-
-